//
//  ViewController.m
//  UIAlertView和UIActionSheet和UIAlertController
//
//  Created by mafeng on 16/8/17.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate, UIAlertViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
  }


- (IBAction)alertView:(id)sender {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"向你问个好" message:@"你好" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [alertView addButtonWithTitle:@"马峰"];
    // 设置警告框风格
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    // 显现警告框
     [alertView show];
    
}


- (IBAction)alertSheet:(id)sender {
    
     UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"向你问个好" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"哈哈" otherButtonTitles:@"other", nil];
    
    [sheet showInView:self.view];
    
}



- (IBAction)alertController:(id)sender {
    
    // uialertAction
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"弹出框" message:@"这是一个弹出框" preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }]];
    
    
    [self presentViewController:alertController animated:NO completion:^{
        
        
    }];
    
}




// alertView的协议方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"点击button%ld", buttonIndex);
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"将要消失%ld", buttonIndex);
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"已经消失%ld", buttonIndex);
}

- (void)alertViewCancel:(UIAlertView *)alertView {
    NSLog(@"取消");
}
// 将第一个按钮变为不可点击的
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView {
    return YES;
}




// actionSheet 的协议方法
- (void)actionSheetCancel:(UIActionSheet *)actionSheet {
    NSLog(@"取消");
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"点击%ld", buttonIndex);
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"已经消失%ld", buttonIndex);
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
     NSLog(@"将要消失%ld", buttonIndex);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
